<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .container {
            display: flex;
            width: 300px;
            height: 100px;
            margin: 100px;
            overflow-x: scroll;
            border: 1px solid #333;
            color:#fff;
            text-align: center;
            line-height: 80px;
            /* mandatory 表示强制吸附 */
            scroll-snap-type: x mandatory;
        }

        .item {
            flex-shrink: 0;
            width: 100%;
            height: 100px;
            /* 吸附对齐方式 */
            scroll-snap-align: start;
            /* 如果快速滑动，也要到下个元素暂停 */
            scroll-snap-stop: always;
        }

        .item:nth-child(1) {
            background-color: rgb(191, 73, 214);
        }

        .item:nth-child(2) {
            background-color: rgb(133, 214, 79);
        }

        .item:nth-child(3) {
            background-color: rgb(66, 144, 218);
        }
        /* ============================================================= */
        .container2 {
            width: 500px;
            height: 500px;
            margin: 100px;
            overflow-y: scroll;
            border: 1px solid #333;
            color:#fff;
            text-align: center;
            line-height: 80px;
            /* proximity 表示到元素附近的时候吸附 */
            scroll-snap-type: y proximity;  
        }
        .item2 {
            width: 100%;
            height: 100%;
            scroll-snap-align: start;
            scroll-snap-stop: always;
        }

        .item2:nth-child(1) {
            background-color: rgb(191, 73, 214);
        }

        .item2:nth-child(2) {
            background-color: rgb(133, 214, 79);
        }

        .item2:nth-child(3) {
            background-color: rgb(66, 144, 218);
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
    <div class="container2">
        <div class="item2">1</div>
        <div class="item2">2</div>
        <div class="item2">3</div>
    </div>
</body>

</html>